package com.lelouch.concurrency.example.immutable;

import com.google.common.collect.Maps;
import com.lelouch.concurrency.annotation.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.Map;

/**
 * 不可变类Collections.unmodifiableXXX
 *
 *
 * @author lcy
 * @create 2018-05-23 16:01
 */
@Slf4j
@ThreadSafe
public class ImmutableExample2 {


    private static Map<Integer,Integer> map = Maps.newHashMap();



    static{

        map.put(1,2);
        map.put(3,4);
        map = Collections.unmodifiableMap(map);


    }

    public static void main(String[] args) {
        map.put(5,6);//该步骤无法执行
        log.info("{}",map.get(5));
    }
}
